﻿using UnityEngine;
using System.Collections;

public class EnemyPlane : Plane
{
	//修饰符 数据类型 变量名
	private Rigidbody2D rig;
	public float speed=13f;//速度
	public GameObject bulletPrefab;//子弹预制体
	public float shootInterval=5f;//发射子弹的间隔

	protected override void Start()
	{
		base.Start ();
		//获取刚体组件
		rig = GetComponent<Rigidbody2D> ();
		rig.velocity = Vector2.down * speed;

		if (bulletPrefab!=null)
		{
			//重复发射子弹
			InvokeRepeating ("Shoot",Random.Range(0f,1f),shootInterval);
		}
		else
		{
			//旋转
			rig.AddTorque (50*(Random.Range(0,2)==0?-1:1));//加扭力
		}
	}

	//发射一颗子弹
	void Shoot()
	{
		//在飞机的位置生成一颗子弹
		Instantiate( bulletPrefab,transform.position,transform.rotation);
	}

}
